"use strict";
const electron = require("electron");
const oracledb = require("oracledb");
let connection = null;
async function runDataBase(config) {
  console.log(config, "config");
  oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
  oracledb.initOracleClient();
  connection = await oracledb.getConnection(config);
  return true;
}
let closeDataBase = async () => {
  if (connection != null) {
    await connection.close();
  }
  return true;
};
let exectureSQL = async (SQLString) => {
  return await connection.execute(SQLString);
};
const { ipcMain } = require("electron");
let functionJSON = {
  runDataBase,
  closeDataBase,
  exectureSQL
};
ipcMain.on("runDataBase", (event, arg) => {
  let exeFunction = functionJSON[arg.type];
  console.log(exeFunction, "exeFunction");
  exeFunction(arg.data).then((res) => {
    event.sender.send(arg.type, res);
  });
});
electron.app.whenReady().then(() => {
  const win = new electron.BrowserWindow({
    title: "Main window",
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  });
  if (process.env.VITE_DEV_SERVER_URL) {
    win.loadURL(process.env.VITE_DEV_SERVER_URL);
  } else {
    win.loadFile("dist/index.html");
  }
  electron.session.defaultSession.loadExtension(
    `C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\nhdogjmejiglipccpnnnanhbledajbpd\\6.5.1_0`
  );
});
